/**
 * @param {string} s1
 * @param {string} s2
 * @return {boolean}
 */
var CheckPermutation = function (s1, s2) {
	if (s1.length !== s2.length) return false
	const map = new Map()
	for (let i = 0; i < s1.length; i++) {
		map.set(s1[i], (map.get(s1[i]) || 0) + 1)
	}
	for (let i = 0; i < s2.length; i++) {
		const cur = s2[i]
		if (!map.has(cur)) return false
		map.set(cur, map.get(cur) - 1)
		if (map.get(cur) < 0) {
			return false
		}
	}
	return true
}

var CheckPermutation = function (s1, s2) {
	return (
		s1.length === s2.length &&
		[...s1].sort().join('') === [...s2].sort().join('')
	)
}
const result = CheckPermutation('abc', 'bca')
console.log('CheckPermutation :>>', result)
